<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
 * 模块:后台会员Models
 * 开发:胡耆英
 * 创建日期: 2011-05-31
 */
class Member_model extends CI_Model
{
	public function __construct()
	{
		parent::__construct();
	}
	
	//会员列表
	public function member_list()
	{
		return $this->db->select('*')->from('member')->order_by('id','desc')->get()->result_array();
	}
	//检查会员账号是否存在
	public function check_account($account)
	{
		return $this->db->select('account')->from('member')->where('account',$account)->get()->row_array();
	}
	//添加会员
	public function add_member($data)
	{
		return $this->db->insert('member',$data);
	}
    /*
     * 会员订单
     * $where 订单查询条件
     * $limit 需要分页的条数
     * $offset 偏移量
     * 
     */
    public function check_order($where,$limit,$offset,$total_count,$page)
    {
        $this->db->select('*');
        $this->db->join('(`ship` , `shop` )','orders.shipid=ship.id AND `orders`.`shopid` = `shop`.`id`','left');
        $this->db->where($where);
        $query = $this->db->get('orders',$limit,$offset);
        if($query)
        {
            $pagination = '';
            if($total_count > $limit)
            {
                $this->load->library('dpagination');
                $this->dpagination->currentPage($page);
                $this->dpagination->items($total_count);
                $this->dpagination->limit($limit);
                $this->dpagination->adjacents(5);
                $this->dpagination->parameterName('p');
                $this->dpagination->nextLabel('下一页');
                $this->dpagination->PrevLabel('上一页');
                $pagination = $this->dpagination->getOutput();
            }
            $output['count'] =	$total_count;
            $output['html']	 =	$pagination;
            $output['data']	 =	$query->result_array();
        }
        else
        {
            $output['count'] =	0;
            $output['html']	 =	'';
            $output['data']	 =	'';
        }
        return $output;
    }
}
?>